package com.gitee.wsl.struct.tree.matcher

import com.gitee.wsl.struct.compare.diff.matcher.MappingStore
import com.gitee.wsl.struct.compare.diff.matcher.Matcher
import com.gitee.wsl.struct.tree.TreeNode


open class TopDownMatcher<T:Any,CONFIG> : Matcher<TreeNode, CONFIG> {

    override fun match(src: TreeNode, dst: TreeNode, mappings: MappingStore<TreeNode>): MappingStore<TreeNode> {
        recursiveMatch(src, dst, mappings)
        return mappings
    }

    private fun recursiveMatch(src: TreeNode, dst: TreeNode, mappings: MappingStore<TreeNode>) {
        /*if (!src.hasSameType(dst)) throw RuntimeException(
            String.format("Top down matching aborted due to a type difference between %s and %s", src, dst)
        )
        if (src.getChildren().size != dst.getChildren().size)
            throw RuntimeException(java.lang.String.format("Top down matching aborted due to a children difference between %s and %s", src.toString(), dst.toString())
        )
        mappings.addMapping(src, dst)
        for (i in 0 until src.getChildren().size)
            recursiveMatch(src.getChild(i), dst.getChild(i), mappings)*/
    }

    override fun config(block: CONFIG.() -> Unit) {

    }
}